package com.winai.launcher.override;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.widget.TextView;

public class GradientColorTextView extends TextView {
    private LinearGradient mLinearGradient;
    private Paint mPaint;
    private int mViewWidth = 0;
    private Rect mTextBound = new Rect();

    public GradientColorTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        LinearGradient mLinearGradient = new LinearGradient(
                0
                , 0
                , getPaint().getTextSize() * getText().length()
                , 0
                , Color.parseColor("#FF669262")
                , Color.parseColor("#FF7eb779")
                , Shader.TileMode.CLAMP);
        getPaint().setShader(mLinearGradient);
        invalidate();
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
//        mViewWidth = getMeasuredWidth();
//        mPaint = getPaint();
//        String mTipText = getText().toString();
//        mPaint.getTextBounds(mTipText, 0, mTipText.length(), mTextBound);
//        mLinearGradient = new LinearGradient(
//                0
//                , 0
//                , mViewWidth
//                , 0
//                , Color.parseColor("#669262")
//                , Color.parseColor("#7eb779")
//                , Shader.TileMode.CLAMP);
//        mPaint.setShader(mLinearGradient);
//        canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 + mTextBound.height() / 2, mPaint);
    }
}
